package com.coolwen.permission;

import org.apache.log4j.Logger;
import org.apache.shiro.authz.Permission;
import org.apache.shiro.util.AntPathMatcher;
import org.apache.shiro.util.PatternMatcher;

/**
 * Created by user on 2016/6/26.
 */
public class UrlPermission implements Permission {
    private Logger logger = Logger.getLogger(getClass());

    private String url;

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public UrlPermission() {
    }

    public UrlPermission(String url) {


        this.url = url;
    }

    @Override
    public boolean implies(Permission p) {
        logger.info("P进入UrlPermission:" +p);
        if(!(p instanceof UrlPermission)) {
            return false;
        }
        UrlPermission up = (UrlPermission) p;

        logger.info("UP进入UrlPermission:" +up.getUrl());
        // /admin/role/**
        PatternMatcher patternMatcher = new AntPathMatcher();

        System.out.println(this.getUrl()+","+up.getUrl()+","+patternMatcher.matches(this.getUrl(), up.getUrl()));
        return patternMatcher.matches(this.getUrl(), up.getUrl());
    }
}
